package com.wwh.spring.process;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.stereotype.Component;

/**
 * @author Albert
 * @date 2024/8/27-19:23
 * @describe
 */
//@Component
public class MyBeanPostProcessor implements BeanPostProcessor {
    /**
     * 在bean的init方法前调用
     * @param bean
     * @param beanName
     * @return
     * @throws BeansException
     */
    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
        //System.out.println("postProcessBeforeInitialization 后置处理器被调用 -- " + beanName);
        System.out.println("postProcessBeforeInitialization 后置处理器被调用 -- " + bean);
        return bean;
    }

    /**
     * 在bean的init方法后调用
     * @param bean
     * @param beanName
     * @return
     * @throws BeansException
     */
    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        //System.out.println("postProcessAfterInitialization 后置处理器被调用 -- " + beanName);
        System.out.println("postProcessAfterInitialization 后置处理器被调用 -- " + bean);
        return bean;
    }
}
